package po;

import java.io.Serializable;
import java.util.Calendar;

public class GiftPO implements Serializable {
	private static final long serialVersionUID = 1429615576039960442L;
	private int id;
	private Calendar beginDate;
	private Calendar endDate;
	private GiftType type;
		
	public GiftPO(){
		this.id=0;
		this.beginDate=null;
		this.endDate=null;
		this.type=null;
	}

	public GiftPO( Calendar beginDate, Calendar endDate,GiftType type) {
		this.beginDate = beginDate;
		this.endDate = endDate;
		this.type=type;
	}

	public GiftPO(GiftPO po){
		this.id=po.id;
		this.beginDate=(Calendar)po.beginDate.clone();
		this.endDate=(Calendar)po.endDate.clone();
		this.type=po.type;
		//拷贝构造函数要是实现的话子类就不成立然后就要重新写逻辑所以拷贝构造函数再见(｀��ω����)，写来是安慰组长的（哪里安慰	
	}
	
	@Override//needed modify
	public String toString() {
		return "GiftPO [id=" + id + ", beginDate=" + getBeginDateFormat()
				+ ", endDate=" + getEndDateFormat() + ", type="+this.type;
	}

	//hashCode here
	public void setId(int id){
		this.id=id;
	}
	public int getId() {
		return id;
	}

	public Calendar getBeginDate() {
		return beginDate;
	}

	public String getBeginDateFormat() {
		return beginDate.get(Calendar.YEAR) + "-"
				+ ( beginDate.get(Calendar.MONTH) + 1 )+ "-"
				+ beginDate.get(Calendar.DATE);
	}

	public Calendar getEndDate() {
		return endDate;
	}

	public String getEndDateFormat() {
		return endDate.get(Calendar.YEAR) + "-"
				+ (endDate.get(Calendar.MONTH) + 1 )+ "-"
				+ endDate.get(Calendar.DATE);
	}

	public GiftType getType() {
		return type;
	}

	public void setGiftType(GiftType type){
		this.type=type;
	}
	
	public boolean isValid() {
	 	if (beginDate == null) {
			return false;
		}
		if (endDate == null) {
			return false;
		}
		Calendar today = Calendar.getInstance();
		if (today.before(beginDate)) {
			return false;
		}
		if (today.after(endDate)) {
			return false;
		}
		return true;
     }
	
	public String getDescription(){
		return null;
	}

	public boolean isAvailable(){
		if (beginDate == null) {
			return false;
		}
		if (endDate == null) {
			return false;
		}
		Calendar today = Calendar.getInstance();
		if (today.after(endDate)) {
			return false;
		}
		return true;
     }
	
}
